package org.zjt.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.zjt.config.ApplicationProperties;
import org.zjt.annotation.RpcService;
import org.zjt.entity.User;
import org.zjt.facade.IHelloService;

import javax.annotation.PostConstruct;
import java.util.Random;

/**
 * Created by Administrator on 2017/4/13.
 */
@RpcService
public class HelloServiceImpl implements IHelloService {

    private static final Logger LOGGER = LoggerFactory.getLogger(HelloServiceImpl.class);

    @Autowired
    ApplicationProperties applicationConfig ;


    @Override
    public void printHello() {
        try {
            Thread.sleep(new Random().nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LOGGER.info(String.format("无参 ：printHello() 执行"));
    }

    @Override
    public String sayHello(String world) {
        LOGGER.info(String.format("有参 ：sayHello(String world) 执行\t参数：%s",world));
        try {
            Thread.sleep(new Random().nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return world;
    }

    @Override
    public String sayHello(String world, User user) {
        LOGGER.info(String.format("有参 ：sayHello(String world) 执行\t参数：%s",world+","+user.toString()));
        try {
            Thread.sleep(new Random().nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return user.toString();
    }

    @PostConstruct
    public void print(){
        LOGGER.info(JSONObject.toJSONString(applicationConfig));
    }
}
